#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int min;
    int n;
    cin >> n;
    int ret = 0;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        if (i == 0)
        {
            min = tmp;
            continue;
        }
        if (tmp <= min) min = tmp;
        if (tmp - min > ret) ret = tmp - min;
    }
    cout << ret;
}
